package com.ffcs.crmd.tsp.admin.control;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ctg.itrdc.platform.common.entity.PageInfo;
import com.ctg.itrdc.platform.common.exception.ExceptionUtil;
import com.ffcs.crmd.platform.pub.vo.RetVo;
import com.ffcs.crmd.tsp.admin.api.dto.JobIdentityInfoDTO;
import com.ffcs.crmd.tsp.admin.api.facade.IJobIdentityInfoFacade;

/**
 * 
 * 功能说明:任务控制层
 *
 * @author ZHONGFUHUA
 * 
 * @Date 2016年2月16日 下午4:49:00
 *
 * 版本号 | 作者 | 修改时间 | 修改内容
 *
 */
@Controller
@ResponseBody
@RequestMapping("/tsp/jobIdentityInfo")
public class JobIdentityInfoController {
    
    private final Logger           logger = LoggerFactory.getLogger(JobIdentityInfoController.class);
    
    @Autowired
    private IJobIdentityInfoFacade jobIdentityInfoFacade;
    
    /**
     * 
     * 功能说明:新增任务
     * 
     * @author ZHONGFUHUA
     *
     * @Date 2016年2月17日
     *
     */
    @RequestMapping(value = "/add")
    public RetVo add(ModelMap map, HttpSession httpSession, @RequestBody JobIdentityInfoDTO taskRegisterInfoDTO) {
        RetVo retVo = new RetVo(true);
        try {
            jobIdentityInfoFacade.save(taskRegisterInfoDTO);
        } catch (Exception e) {
            logger.error("JobIdentityInfoController : add job identity info exception:", e);
            retVo.setResult(false);
            retVo.setMsgTitle(e.getMessage());
            retVo.setDetailMsg(ExceptionUtil.getTraceInfo(e));
        }
        return retVo;
    }
    
    
    /**
     * 
     * 功能说明:新增任务
     * 
     * @author ZHONGFUHUA
     *
     * @Date 2016年2月17日
     *
     */
    @RequestMapping(value = "/addList")
    public RetVo addList(ModelMap map, HttpSession httpSession, @RequestBody List<JobIdentityInfoDTO> taskRegisterInfoDTOList) {
        RetVo retVo = new RetVo(true);
        try {
            jobIdentityInfoFacade.save(taskRegisterInfoDTOList);
        } catch (Exception e) {
            logger.error("JobIdentityInfoController : add job identity info exception:", e);
            retVo.setResult(false);
            retVo.setMsgTitle(e.getMessage());
            retVo.setDetailMsg(ExceptionUtil.getTraceInfo(e));
        }
        return retVo;
    }
    
    @RequestMapping(value = "/get")
    public RetVo get(ModelMap map, HttpSession httpSession, @RequestBody JobIdentityInfoDTO jobIdentityInfoDTO) {
        RetVo retVo = new RetVo(true);
        try {
            JobIdentityInfoDTO rjobIdentityInfoDTO = jobIdentityInfoFacade.get(jobIdentityInfoDTO);
            retVo.setObject(rjobIdentityInfoDTO);
        } catch (Exception e) {
            logger.error("JobIdentityInfoController : get job identity info exception:", e);
            retVo.setResult(false);
            retVo.setMsgTitle(e.getMessage());
            retVo.setDetailMsg(ExceptionUtil.getTraceInfo(e));
        }
        return retVo;
    }
    
    
    /**
     * 
     * 功能说明:删除任务
     * 
     * @author ZHONGFUHUA
     *
     * @Date 2016年2月17日
     *
     */
    @RequestMapping(value = "/delete")
    public RetVo remove(ModelMap map, HttpSession httpSession, @RequestBody JobIdentityInfoDTO jobIdentityInfoDTO) {
        RetVo retVo = new RetVo(true);
        try {
            jobIdentityInfoFacade.remove(jobIdentityInfoDTO);
        } catch (Exception e) {
            logger.error("JobIdentityInfoController : delete job identity info exception:", e);
            retVo.setResult(false);
            retVo.setMsgTitle(e.getMessage());
            retVo.setDetailMsg(ExceptionUtil.getTraceInfo(e));
        }
        return retVo;
    }
    
    /**
     * 
     * 功能说明:查询所有任务
     * 
     * @author ZHONGFUHUA
     *
     * @Date 2016年2月17日
     *
     */
    @RequestMapping(value = "/queryPage")
    public RetVo queryPage(ModelMap map, HttpSession httpSession, @RequestBody JobIdentityInfoDTO jobIdentityInfoDTO) {
        RetVo retVo = new RetVo(true);
        try {
            PageInfo<JobIdentityInfoDTO> pageInfo = jobIdentityInfoFacade.queryPage(jobIdentityInfoDTO);
            retVo.setPageInfo(pageInfo);
        } catch (Exception e) {
            logger.error("JobIdentityInfoController : query all job identity info exception:", e);
            retVo.setResult(false);
            retVo.setMsgTitle(e.getMessage());
            retVo.setDetailMsg(ExceptionUtil.getTraceInfo(e));
        }
        return retVo;
    }
    
}
